import { store as storeInstance } from '@/config'
import type { TupleToObject } from '@/types'

/**
 * store外部使用
 */
export function withStoreOut<T extends (...args: any) => any>(store: T) {
  return () =>
    store(storeInstance)
}

/**
 * 将返回结果为元组的hook(方法) 转换返回结果为 对象
 */
export function withTupleToObject<
  T extends string[],
  F extends (...args: any[]) => any = (
    ...args: any[]
  ) => any,
>(fn: F, params: T) {
  return (...args: Parameters<F>) => {
    const tupleRes = fn(...args)
    const objRes: Record<string, any> = {}
    for (const i in params) {
      objRes[params[i]!] = tupleRes[i]
    }
    return objRes as TupleToObject<
      Awaited<ReturnType<F>>,
      T
    >
  }
}

/**
 * 将返回结果为对象的hook(方法) 转换返回结果为 元组
 */
export function withObjectToTuple() {}
